using UnityEngine;
using QFramework;
using QAssetBundle;

namespace ProjectSurviver
{
	public partial class GetAllExp : GamePlayObject
	{
        public override Collider2D Collider2D => SelfCollider2D;

        void OnTriggerEnter2D(Collider2D other)
        {
            if(other.GetComponent<CollectableArea>())
			{
				foreach (var exp in FindObjectsByType<Exp>(FindObjectsInactive.Exclude, FindObjectsSortMode.None))
				{
					ActionKit.OnUpdate.Register(() =>
					{
						var player= Player.Default;
						if(player)
						{
							var direction = player.Position() - exp.Position();
							exp.transform.Translate(direction * Time.deltaTime * 2.5f);
						}
					}).UnRegisterWhenGameObjectDestroyed(exp);
				}
				AudioKit.PlaySound(Sfx.GETALLEXP);
				this.DestroyGameObjGracefully();
			}
        }
    }
}
